import fetch from 'common/src/utils/fetch';
import baseUrl from './env';
import fileUrl from './env';
import UTILS from "common/src/utils/utils";

/**
 *  课程管理
 */

// 上传课程资料2
function getBase64(data) {
  return fetch({
    url: `${baseUrl}/behavior/courseMaterial/getBase64?key=` + data,
    method: 'get',
    data
  });
}

// 学生查看课程列表
function getLearningPage(data) {
  return fetch({
    url: `${baseUrl}/behavior/courseLearning/getLearningPage`,
    method: 'Post',
    data
  });
}

// 课程管理查询列表
function getCourseList(data) {
  return fetch({
    url: `${baseUrl}/behavior/behaviorcourse/getCourseList`,
    method: 'Post',
    data
  });
}

// 课程管理新增
function addCourse(data) {
  return fetch({
    url: `${baseUrl}/behavior/behaviorcourse/addCourse`,
    method: 'Post',
    data
  });
}

// 学院下拉接口
function facultyList(data) {
  return fetch({
    url: `${baseUrl}/behavior/behaviorcourse/facultyList`,
    method: 'Post',
    data
  });
}

// 课程资料详情
function getById(data) {
  return fetch({
    url: `${baseUrl}/behavior/behaviorcourse/getById?id=` + data,
    method: 'get',
    data
  });
}

// 删除课程资料
function deleteCourse(data) {
  return fetch({
    url: `${baseUrl}/behavior/behaviorcourse/deleteCourse`,
    method: 'Post',
    data
  });
}

// 编辑课程资料
function editCourse(data) {
  return fetch({
    url: `${baseUrl}/behavior/behaviorcourse/editCourse`,
    method: 'Post',
    data
  });
}

// 发布课程
function releaseCourse(data) {
  return fetch({
    url: `${baseUrl}/behavior/behaviorcourse/releaseCourse`,
    method: 'Post',
    data
  });
}

// 取消课程
function cancelPostCourse(data) {
  return fetch({
    url: `${baseUrl}/behavior/behaviorcourse/cancelPostCourse`,
    method: 'Post',
    data
  });
}

// 导出课程
function exportCourse(data) {
  return fetch({
    url: `${baseUrl}/behavior/behaviorcourse/export`,
    method: 'Post',
    responseType: 'blob',
    data
  }).then(res => {
    UTILS.downloadFile(res, '课程管理.xls', 'application/vnd.ms-excel;charset=utf-8');
  });
}


// 获取审核列表
function getApproveList(data) {
  return fetch({
    url: `${baseUrl}/behavior/behaviorcourse/getApproveList`,
    method: 'Post',
    data
  });
}

// 审核通过
function approveAgree(data) {
  return fetch({
    url: `${baseUrl}/behavior/behaviorcourse/approveAgree`,
    method: 'Post',
    data
  });
}

// 审核驳回
function approveRefuse(data) {
  return fetch({
    url: `${baseUrl}/behavior/behaviorcourse/approveRefuse`,
    method: 'Post',
    data
  });
}

// 文件从obs转换到预览服务过程1：将文件转为字节数组
function fileToByteArray(data) {
  return fetch({
    url: `${baseUrl}/behavior/courseMaterial/fileToByteArray?id=` + data,
    method: 'get',
    data
  });
}

// 更新学习状态
function updateLearningStatus(data) {
  return fetch({
    url: `${baseUrl}/behavior/courseLearning/updateLearningStatus`,
    method: 'Post',
    data
  });
}

// 学生查看课程详情
function getDetail(data) {
  return fetch({
    url: `${baseUrl}/behavior/courseLearning/getDetail?id=` + data,
    method: 'get',
    data
  });
}


export default {
  'getBase64': getBase64,
  'getLearningPage': getLearningPage,
  'getCourseList': getCourseList,
  'addCourse': addCourse,
  'facultyList': facultyList,
  'getById': getById,
  'deleteCourse': deleteCourse,
  'editCourse': editCourse,
  'releaseCourse': releaseCourse,
  'cancelPostCourse': cancelPostCourse,
  'exportCourse': exportCourse,
  'getApproveList': getApproveList,
  'approveAgree': approveAgree,
  'approveRefuse': approveRefuse,
  'fileToByteArray': fileToByteArray,
  'updateLearningStatus': updateLearningStatus,
  'getDetail': getDetail

};
